﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Snowdreamist.Collection.Tree
{
    public interface ITreeNode<T> where T : ITreeNode<T>
    {
        T Parent { get; }

        /// <summary>
        /// The children of this node
        /// NOTE:
        ///     This property cannot be null
        /// </summary>
        ITreeNodeCollection<T> Children { get; }

        /// <summary>
        /// Create navigator
        /// </summary>
        /// <returns></returns>
        ITreeNodeNavigator<T> CreateNavigator();

        /// <summary>
        /// Get the root node
        /// </summary>
        T Root { get; }

        /// <summary>
        /// Is two tree nodes equal
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        bool TreeNodeEquals(ITreeNode<T> other);

        /// <summary>
        /// If the two tree nodes come from the same node
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        bool IsSameRoot(ITreeNode<T> other);

        /// <summary>
        /// Attach this node to a parent tree node
        /// NOTE: One node could only have one parent
        /// NOTE: This method will not affect parent node, just change the state of this node
        /// </summary>
        /// <param name="parent"></param>
        void Attach(ITreeNode<T> parent);

        /// <summary>
        /// Detach this node from parent
        /// NOTE: This method will not affect parent node, just change the state of this node
        /// </summary>
        bool Detach();

        /// <summary>
        /// Is this node attached
        /// </summary>
        bool IsAttached { get; }

        /// <summary>
        /// tostring
        /// </summary>
        /// <param name="indent"></param>
        /// <returns></returns>
        void ToString(int indent, StringBuilder strBuilder);
    }
}